package com.jdk.learn.juc2.thread;

/**
 * 类功能描述:
     * one:true
     * one:true
     * main ::false
     * one:true
     * main ::false
 线程发生中断时 会通知sleep的(java.lang.InterruptedException: sleep interrupted)  但是会重置 interrupted 的status 为false
 * @author bgt
 * @version V1.0
 * @since 2019-01-31 15:07
 */
public class ThreadInterupt {
    public static void main(String[] args) throws InterruptedException {
        Thread one=new Thread(()->{
            int i=0;
            for(;;){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                    Thread thread = Thread.currentThread();
                    boolean interrupted =thread .isInterrupted();
                    System.out.println(thread.getName()+":"+interrupted);
                    if (interrupted){
                        break;
                    }
            }
        },"rickybai222");
        one.start();
        Thread.sleep(100);
        one.interrupt();
        System.out.println("one:"+one.isInterrupted());
        one.interrupt();
        System.out.println("one:"+one.isInterrupted());
        System.out.println(Thread.currentThread().getName()+" ::"+Thread.interrupted());
        System.out.println("one:"+one.isInterrupted());
        System.out.println(Thread.currentThread().getName()+" ::"+Thread.currentThread().isInterrupted());

        one.join();
    }
}
